/**
 * http.js
 * 作用：封装post请求
 * author：xxx  date：2022-5-5
 */
 function formatObj(obj){
    let str = '';
    for(key in obj){
        str+='&'+key+'='+obj[key];
        str=str.slice(1)
    }
    return str;
}
const http={
    post:function(url,obj,callback){
        let xhr = new XMLHttpRequest();
        xhr.open('post',url);
        xhr.setRequestHeader('Content-Type','application/json');
        xhr.send(JSON.stringify(obj));
        xhr.onreadystatechange=function(){
            if(xhr.readyState==4&&xhr.status==200){
                callback(JSON.parse(xhr.responseText))
            }
        }
    }
}
window.http=http;